package com.cat.greedyAlgorithm;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/minimum-rectangles-to-cover-points/description/
 * @create 2025/8/25 14:37
 * @since JDK17
 */

public class Solution33 {
    public int minRectanglesToCoverPoints(int[][] points, int w) {
        int n = points.length, ans = 0;
        Arrays.sort(points, (o1, o2) -> o1[0] - o2[0]); // 根据x排升序
        for (int i = 0; i < n; ) {
            int x = points[i][0];
            while (i < n && points[i][0] - x <= w) {
                i++;
            }
            ans++;
        }

        return ans;
    }
}
